import common.CommonDemo;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.time.Duration;

public class AddCookie {

    private CommonDemo commonDemo;
    private WebDriver driver;
    private WebDriverWait wait;
    private String cookieValue;

    @BeforeTest
    public void setUp() throws Exception{
        commonDemo = new CommonDemo();
        driver = commonDemo.getChromeDriver();
        wait = new WebDriverWait(driver, Duration.ofSeconds(2));
        cookieValue = commonDemo.getPropertyValue("config.properties", "cookie.value");

    }
    @Test
    public void test() throws Exception{
        String url = "https://www.baidu.com";
        driver.get(url);
        driver.manage().window().maximize();
        Cookie cookie = new Cookie("Cookie", cookieValue);
        driver.manage().addCookie(cookie);
    }
    @AfterTest
    public void tearDown() throws Exception{
        Thread.sleep(2000);
        driver.quit();
    }
}
